"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Hall_1 = __importDefault(require("../models/Hall"));
const __1 = require("..");
const Room_1 = __importDefault(require("../models/Room"));
async function default_1(call) {
    let { room, type, content } = call.req;
    // 服务器
    const roomSever = Room_1.default.instance.get(room.id);
    if (roomSever) {
        // 同步room状态
        roomSever.status = room.status;
        // 广播群体
        const connArr = [];
        roomSever.players.forEach(player => {
            if (player.openid) {
                connArr.push(Hall_1.default.instance.get(player.openid));
                if (type == 'msg_game_start') {
                    player.status = 1;
                }
                else if (type == 'msg_game_restart') {
                    const temp = room.players.find(v => v.openid == player.openid);
                    if (temp)
                        player.status = temp.status;
                }
            }
        });
        if (type == 'msg_game_start' || type == 'msg_game_restart') {
            Room_1.default.instance.refreshHall();
        }
        // 广播内容
        const msg = {
            type,
            content
        };
        __1.server.broadcastMsg('GameRefresh', msg, connArr);
    }
    call.succ({});
}
exports.default = default_1;
